#ifndef _MW_MESSAGE_QUEUE_H
#define _MW_MESSAGE_QUEUE_H


/*
  Meanwhile - Unofficial Lotus Sametime client library
  
  Copyright (c) 2007 Christopher O'Brien <siege@preoccupied.net>
  
  License: LGPL
  
  This library is free software; you can redistribute it and/or modify
  it under the terms of version 2 the GNU Library General Public
  License as published by the Free Software Foundation.
                                                                                
  This library is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Library General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  USA
*/


#include <glib.h>


G_BEGIN_DECLS


typedef struct mw_queue MwQueue;


MwQueue *mw_queue_new(GDestroyNotify clear_item);


/** empties the queue, calling the clear_item function on each item in
    turn. */
void mw_queue_clear(MwQueue *queue);


/** empties the queue, calling the clear_item function on each item in
    turn, then destroys the queue */
void mw_queue_free(MwQueue *queue);


/** Appends an item to the queue */
void mw_queue_add(MwQueue *queue, gpointer item);


/** returns the current item in the queue, or NULL if the queue is
    empty. If non-NULL, this function will return the same item until
    mw_queue_turn is called to move to the next item. */
gpointer mw_queue_current(MwQueue *queue);


/** removes the first item in the queue (calling the cleanup function
    if one was specified to mw_queue_new) and moves to the next item
    and returns it. */
gpointer mw_queue_next(MwQueue *queue);


/** number of items in the queue */
guint mw_queue_count(MwQueue *queue);


typedef struct mw_keyed_queue MwKeyedQueue;


MwKeyedQueue *mw_keyed_queue_new(GDestroyNotify clear_item,
				 GHashFunc hash_key, GEqualFunc equal_key,
				 GDestroyNotify clear_key);


void mw_keyed_queue_clear(MwKeyedQueue *queue);


/** drops all items in the key's queue */
void mw_keyed_queue_clear_key(MwKeyedQueue *queue, gpointer key);


void mw_keyed_queue_free(MwKeyedQueue *queue);


/** add an item to the key's queue */
void mw_keyed_queue_add(MwKeyedQueue *queue, gpointer key, gpointer item);


/** get the current item in the queue */
gpointer mw_keyed_queue_current(MwKeyedQueue *queue);


/** drop the current item in the queue, move to the next and return it */
gpointer mw_keyed_queue_next(MwKeyedQueue *queue);


/** count of items in a key's queue */
guint mw_keyed_queue_count_key(MwKeyedQueue *queue, gpointer key);


/** count of all items in all key's queues */
guint mw_keyed_queue_count(MwKeyedQueue *queue);


G_END_DECLS


#endif /* _MW_MESSAGE_QUEUE_H */
